//
// Created by changlei on 2022/4/1.
//

import Foundation
import RxDio


/// 网络请求
class Api {
    private init() {
    }

    /// 获取排行列表
    static func getTop250(type: MovieType = .scenario, currentPage: Int = 0, pageSize: Int = 20) async -> [Movie]? {
        try? await decodable(
                "https://movie.douban.com/j/chart/top_list",
                method: .get,
                parameters: [
                    "type": type.rawValue,
                    "interval_id": "100:90",
                    "action": "",
                    "start": currentPage * pageSize,
                    "limit": pageSize
                ])
    }

    /// 获取简介
    static func getSubjects(tag: String, currentPage: Int = 0, pageSize: Int = 20) async -> [Subject]? {
        let subjects = try? await decodable(
                "https://movie.douban.com/j/search_subjects",
                of: Subjects.self,
                method: .get,
                parameters: [
                    "type": "movie",
                    "tag": tag,
                    "page_start": currentPage * pageSize,
                    "page_limit": pageSize,
                    "tdsourcetag": "s_pcqq_aiomsg",
                    "qq-pf-to": "pcqq.c2c"
                ])
        return subjects?.subjects
    }
}